<template>
  <!--这是登录框组件-->
  <div class="login">
    <div class="left">
      <h3>账号密码登录</h3>
      <p>
        推荐使用
        <span>网易云账号</span>登录,相通
      </p>
      <input type="text" placeholder="请输入账号" v-model="use" />
      <input type="text" placeholder="请输入密码" v-model="pass" @keyup.enter="login"/>
      <input class="up" type="button" value="登录" @click="login" />
    </div>
    <div class="right">
      <ul>
        <li>
          <span>桔子音乐</span>将获取以下权限
        </li>
        <li>获取您的昵称 头像 性别</li>
        <li>授权后表明你已同意 网易云登录服务协议</li>
        <li>
          <input type="button" value="同意" />
        </li>
      </ul>
    </div>
    <div class="hengfu">给你一个耳机能否让我开启网易云音乐心动模式</div>
    <status :key1="show" :text="text" />
  </div>
</template>

<script>
import require from "requests/index";
import status from "./status";
export default {
  name: "login",
  data() {
    return {
      use: null,
      pass: null,
      show: false,
      text: null
    };
  },

  components: {
    status
  },
  mounted() {
    
  },
  methods: {
    login() {
      if (this.use !== "" && this.pass !== "") {
        require
          .loginRequire(this.use, this.pass)
          .then(res =>{
              this.show=true
              this.text='登录成功'
              this.hide()
              //console.log(res)
              this.$store.commit('setData',res.data.profile)
              this.escLogin()
              localStorage.userId=res.data.profile.userId
              localStorage.nickname=res.data.profile.nickname
              localStorage.avatarUrl=res.data.profile.avatarUrl
          })
          .catch(rej =>{
              this.show=true
              this.text='登录失败'
              this.hide()
          });
      }
    },
    hide(){
        setTimeout(()=>{
            this.show=false
        },2000)
    },
    escLogin(){
        setTimeout(()=>{
            this.$emit('hide')
        },3000)
        
    }
  }
};
</script>

<style lang="less" scoped>
.login {
  position: relative;
  .left {
    float: left;
    width: 60%;
    height: 300px;
    text-align: center;
    box-sizing: border-box;
    input {
      width: 258px;
      height: 30px;
      border-radius: 4px;
      margin-top: 15px;
    }
    input:focus {
      border: 2px solid #31c27c;
      outline: none;
    }
    .up {
      background: #31c27c;
      color: #fff;
      border: none;
    }
    p {
      span {
        color: #31c27c;
      }
    }
  }
  .right {
    float: right;
    width: 40%;
    text-align: center;
    height: 300px;
    border-left: 1px dotted #c4c1c1;
    box-sizing: border-box;
    ul {
      font-size: 12px;
      li {
        padding: 10px 0;
        border-top: 1px dotted #c4c1c1;
        input {
          background-color: #31c27c;
          border: none;
          padding: 5px 10px;
          color: #fff;
        }
      }
    }
  }
  .hengfu {
    background-color:#31c27c;
    border-radius: 5px;
    line-height: 30px;
    padding: 0 5px;
    height: 30px;
    position: absolute;
    top: 300px;
    left: 180px;
    color: #fff;
  }
  .esc {
    position: absolute;
    background-image: url("~@/assets/img/esc.png");
    background-repeat: no-repeat;
    background-size: contain;
    width: 40px;
    height: 40px;
    top: -45px;
    left: calc(100% - 40px);
  }
}
</style>